﻿using ZYCommon;
using System;
using System.Collections;
using System.Windows.Forms;
using TextEditor.TextDocument.Document;

namespace TextEditor
{    
    public class ZYVBSystem
    {
        internal ZYVBScriptEngine ZYVBEngine = null;
        private ZYTextDocument myOwnerDocument = null;
        private Hashtable mySession = new Hashtable();
        private NameValueList myValues = new NameValueList();
        private string strSystemName = null;

        public ZYVBSystem(ZYTextDocument myDocument)
        {
            this.myOwnerDocument = myDocument;
            this.strSystemName = "电子病历文本编辑器";
        }

        public void Alert(object objText)
        {
            MessageBox.Show(null, this.GetDisplayText(objText), this.strSystemName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            if (this.ZYVBEngine != null)
            {
                this.ZYVBEngine.HasUserInterface = true;
            }
        }

        public bool ConFirm(object objText)
        {
            if (this.ZYVBEngine != null)
            {
                this.ZYVBEngine.HasUserInterface = true;
            }
            return (MessageBox.Show(null, this.GetDisplayText(objText), this.strSystemName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
        }

        public void DebugPrint(object objText)
        {
            Console.WriteLine(this.GetDisplayText(objText));
        }

        public string FixValueString(string strText)
        {
            return this.myValues.FixVariableString(strText);
        }

        public string GetDisplayText(object objData)
        {
            if (objData == null)
            {
                return "[null]";
            }
            return Convert.ToString(objData);
        }

        public string GetValue(string strName)
        {
            return this.myValues.GetValue(strName);
        }

        public string Prompt(object objCaption, object objDefault)
        {
            if (this.ZYVBEngine != null)
            {
                this.ZYVBEngine.HasUserInterface = true;
            }
           // return dlgInputBox.InputBox(this.strSystemName, this.GetDisplayText(objCaption), this.GetDisplayText(objDefault));
            return null;
        }

        public void SetValue(string strName, string strValue)
        {
            this.myValues.SetValue(strName, strValue);
        }

        public Hashtable Session
        {
            get
            {
                return this.mySession;
            }
        }

        public string SystemName
        {
            get
            {
                return this.strSystemName;
            }
        }
    }
}

